Using the :lang() Pseudo-Class in CSS
The :lang() pseudo-class in CSS allows you to target elements based on their language attribute (lang). This is useful for applying language-specific styling, such as font, text direction, or typographic rules.
:lang(language-code) – Selects elements whose language matches the specified code, e.g., :lang(en) for English or :lang(fr) for French.
Matches both the lang attribute on the element and inherited language from parent elements.
Useful for internationalization, styling multilingual content differently.
In this example, the English paragraph uses Arial and navy text, while the French paragraph uses Times New Roman and dark red text, demonstrating language-specific styling with :lang().
Use :lang() for multilingual websites to enhance readability and cultural appropriateness.
Combine with other pseudo-classes like :first-letter or :first-line for detailed typographic styling.
Ensure correct lang attributes are set on elements to make this pseudo-class effective.
Test across browsers as support is broad but always verify inherited language behavior.
You're building a bilingual blog where French paragraphs need italic styling — how would you use :lang() to target them correctly?
A user reports that Spanish text isn't showing the right font — you see the HTML has lang='es', but your CSS uses :lang(spanish). What's wrong?
How would you write a CSS rule to apply a different quotation style only to German text inside a div with lang='de'?
Our multilingual app has dynamic content loaded via API — sometimes the lang attribute is missing or inconsistent. How would you debug why :lang() styles aren't applying in production?
We're using :lang() to adjust punctuation spacing for Japanese vs English, but users on iOS Safari report inconsistent rendering. What could be causing this, and how would you fix it?
A designer wants to use :lang() to change font weights for Arabic text, but the site also uses a CMS that sometimes outputs lang='ar-SA' and other times lang='ar'. How would you handle this ambiguity?
We're redesigning our global content platform and need to support over 20 languages with custom typography. How would you architect the CSS strategy using :lang() without creating a maintenance nightmare?
A performance audit shows our CSS bundle is bloated because we're using dozens of :lang() rules. What alternatives or optimizations would you consider, and what tradeoffs do they introduce?
We're migrating from a legacy system that used class-based language targeting to :lang(). What edge cases in content rendering or CMS output might break during this transition?
Our company supports 50+ languages across 10 products — how would you standardize language-based styling across teams without creating CSS fragmentation or accessibility gaps?
We're considering deprecating class-based language styling in favor of :lang(), but legacy content has inconsistent lang attributes. How would you design a migration plan that minimizes UX impact and ensures compliance?
How would you advocate for :lang() as a core accessibility and internationalization primitive in our design system, and what metrics would you track to prove its impact across regions?